import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";

export const Layout = () => import("@/layout/index.vue");

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/redirect",
    component: Layout,
    meta: { hidden: true },
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },

  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    meta: { hidden: true },
  },
  // 机构编辑模板
  {
    path: "/templateManage/depart/:departId",
    name: "DepartTemplateEdit",
    component: () => import("@/views/templateManage/depart/index.vue"),
    meta: { hidden: true, title: "艺术机构模板编辑" },
  },
  // 艺术家编辑模板
  {
    path: "/templateManage/artist/:artistId",
    name: "ArtistTemplateEdit",
    component: () => import("@/views/templateManage/artist/index.vue"),
    meta: { hidden: true, title: "艺术家模板编辑" },
  },
  {
    path: "/artwork/edit/:artistId",
    component: () => import("@/views/artPreferInfo/artwork/index.vue"),
    name: "ArtworkEdit",
    meta: { hidden: true, title: "艺术家艺术品信息" },
  },
  {
    path: "/templateManage/eventExhibition/:eventId",
    name: "EventExhibitionTemplateEdit",
    component: () => import("@/views/templateManage/eventExhibition/index.vue"),
    meta: { hidden: true, title: "活动展览模板设置" },
  },

  {
    path: "/",
    name: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        component: () => import("@/views/dashboard/index.vue"),
        name: "Dashboard", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "首页",
          icon: "homepage",
          affix: true,
          keepAlive: true,
          alwaysShow: false,
        },
      },
      {
        path: "401",
        component: () => import("@/views/error-page/401.vue"),
        meta: { hidden: true },
      },
      {
        path: "404",
        component: () => import("@/views/error-page/404.vue"),
        meta: { hidden: true },
      },
    ],
  },
  {
    path: "/artPreferInfo",
    component: Layout,
    redirect: "/artPreferInfo/depart",
    name: "CnvControl",
    meta: { title: "基础信息", icon: "system" },
    children: [
      {
        path: "depart",
        component: () => import("@/views/artPreferInfo/depart/index.vue"),
        name: "Depart",
        meta: { title: "艺术机构信息" },
      },
      {
        path: "artist",
        component: () => import("@/views/artPreferInfo/artist/index.vue"),
        name: "Artist",
        meta: { title: "艺术家信息" },
      },
      {
        path: "artwork",
        component: () => import("@/views/artPreferInfo/artwork/index.vue"),
        name: "Artwork",
        meta: { title: "艺术品信息" },
      },
      {
        path: "eventExhibition",
        component: () => import("@/views/artPreferInfo/eventExhibition/index.vue"),
        name: "EventExhibition",
        meta: { title: "活动展览信息" },
      },
    ],
  },
  {
    path: "/plate",
    component: Layout,
    redirect: "/plate/article",
    name: "Plate",
    meta: { title: "板块内容", icon: "system" },
    children: [
      {
        path: "indexTemp",
        component: () => import("@/views/templateManage/indexTemp/index.vue"),
        name: "IndexTemp",
        meta: { title: "顶部导航设置" },
      },
      {
        path: "artworkOnline",
        component: () => import("@/views/plate/artworkOnline/index.vue"),
        name: "ArtworkOnline",
        meta: { title: "首页作品在线设置" },
      },
      {
        path: "banner",
        component: () => import("@/views/plate/banner/index.vue"),
        name: "Banner",
        meta: { title: "首页轮播图片设置" },
      },
      {
        path: "eventExhibitionBanner",
        component: () => import("@/views/plate/eventExhibitionBanner/index.vue"),
        name: "EventExhibitionBanner",
        meta: { title: "线上艺术展轮播图片设置" },
      },
      {
        path: "article",
        component: () => import("@/views/plate/article/index.vue"),
        name: "Article",
        meta: { title: "首页文章设置" },
      },
      {
        path: "indexDepart",
        component: () => import("@/views/index/depart/index.vue"),
        name: "IndexDepart",
        meta: { title: "首页艺术机构设置" },
      },
      {
        path: "indexArtist",
        component: () => import("@/views/index/artist/index.vue"),
        name: "IndexArtist",
        meta: { title: "首页艺术家设置" },
      },
      {
        path: "indexArtwork",
        component: () => import("@/views/index/artwork/index.vue"),
        name: "IndexArtwork",
        meta: { title: "首页艺术品设置" },
      },
      {
        path: "picture",
        component: () => import("@/views/plate/picture/index.vue"),
        name: "Picture",
        meta: { title: "图片列表" },
      },
    ],
  },
  {
    path: "/systemResource",
    component: Layout,
    redirect: "/systemResource/artvideo",
    name: "SystemResource",
    meta: { title: "系统资源", icon: "system" },
    children: [
      {
        path: "artVideo",
        component: () => import("@/views/systemResource/artVideo/index.vue"),
        name: "ArtVideo",
        meta: { title: "视频管理" },
      }
    ],
  },
  {
    path: "/system",
    component: Layout,
    redirect: "/system/user",
    name: "System",
    meta: { title: "系统基础设置", icon: "system" },
    children: [

      {
        path: "systemConfig",
        component: () => import("@/views/system/systemConfig/index.vue"),
        name: "SystemConfig",
        meta: { title: "网站设置" },
      },
      {
        path: "user",
        component: () => import("@/views/system/user/index.vue"),
        name: "User",
        meta: { title: "用户设置" },
      },
      {
        path: "templateDetail",
        component: () => import("@/views/system/templateDetail/index.vue"),
        name: "TemplateDetail",
        meta: { title: "模板设置" },
      },
      {
        path: "plateType",
        component: () => import("@/views/system/plateType/index.vue"),
        name: "PlateType",
        meta: { title: "板块内容分类设置" },
      },
      {
        path: "artType",
        component: () => import("@/views/system/artType/index.vue"),
        name: "ArtType",
        meta: { title: "艺术分类设置" },
      },
      {
        path: "indexType",
        component: () => import("@/views/system/indexType/index.vue"),
        name: "IndexType",
        meta: { title: "首页模块设置" },
      },
      {
        path: "departType",
        component: () => import("@/views/system/departType/index.vue"),
        name: "DepartType",
        meta: { title: "机构分类设置" },
      },
      {
        path: "region",
        component: () => import("@/views/system/region/index.vue"),
        name: "Region",
        meta: { title: "区域设置" },
      },
      {
        path: "onlineType",
        component: () => import("@/views/system/onlineType/index.vue"),
        name: "OnlineType",
        meta: { title: "作品在线分类设置" },
      },
    ],
  },
];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

/**
 * 重置路由
 */
export function resetRouter() {
  router.replace({ path: "/login" });
}

export default router;
